10. Solutions: Self JOINs
Self JOINs
SELECT we1.id AS we_id,
we1.account_id AS we1_account_id,
we1.occurred_at AS we1_occurred_at,
we1.channel AS we1_channel,
we2.id AS we2_id,
we2.account_id AS we2_account_id,
we2.occurred_at AS we2_occurred_at,
we2.channel AS we2_channel
FROM web_events we1
LEFT JOIN web_events we2
ON we1.account_id = we2.account_id
AND we1.occurred_at > we2.occurred_at
AND we1.occurred_at <= we2.occurred_at + INTERVAL '1 day'
ORDER BY we1.account_id, we2.occurred_at
Code
If you need a code on the https://github.com/udacity.